package af.Class;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashMap;

import org.apache.struts.util.LabelValueBean;

import af.Form.GenInformeForm;
import af.Form.InformeForm;
import af.Form.ResponsableForm;

public class Informe extends ConexionBD{
	private String sSql;
	private Connection cn = null;
	private Statement st = null;
	private ArrayList<Object> grInforme ;
	
	
	public  ArrayList<Object> RespCombo(){
		ArrayList<Object> resp = new ArrayList<Object>();
		try{
			cn = getConection();
			st = cn.createStatement();
			
			sSql = "Select * FROM actfijo_responsable";
			
			ResultSet rs= st.executeQuery(sSql);
			while(rs.next()){
				resp.add(new LabelValueBean(rs.getObject("IdResponsable").toString(),rs.getObject("Nombre").toString()));
				
			}
			cn.close();
			st.close();
			
		}catch(Exception e){
			System.out.println(e.getMessage());
		
		}
		return resp;
	}
		 
  
	public  ArrayList<Object> UbiCombo(){
		ArrayList<Object> resp = new ArrayList<Object>();
		try{
			cn = getConection();
			st = cn.createStatement();
			
			sSql = "Select * FROM actfijo_ubicacion";
			
			ResultSet rs= st.executeQuery(sSql);
			while(rs.next()){
				resp.add(new LabelValueBean(rs.getObject("IdUbicacion").toString(),rs.getObject("Descripcion").toString()));
				
			}
			cn.close();
			st.close();
			
		}catch(Exception e){
			System.out.println(e.getMessage());
		
		}
		return resp;
	}
	public  ArrayList<Object> MesCombo(){
		ArrayList<Object> mes  ;
		mes = new ArrayList<Object>();
		
		mes.add(new LabelValueBean("Enero","1"));
		mes.add(new LabelValueBean("Febrero","2"));
		mes.add(new LabelValueBean("Marzo","3"));
		mes.add(new LabelValueBean("Abril","4"));
		mes.add(new LabelValueBean("Mayo","5"));
		mes.add(new LabelValueBean("Junio","6"));
		mes.add(new LabelValueBean("Julio","7"));
		mes.add(new LabelValueBean("Agosto","8"));
		mes.add(new LabelValueBean("Septiembre","9"));
		mes.add(new LabelValueBean("Octubre","10"));
		mes.add(new LabelValueBean("Noviembre","11"));
		mes.add(new LabelValueBean("Diciembre","12"));
		
		return mes;
		
	}
	public  ArrayList<Object> AnoCombo(){
		ArrayList<Object> ano = new ArrayList<Object>();
		Integer iano=2000;
		while(iano<2020){
			ano.add(new LabelValueBean("" + iano + "",""+ iano + ""));
			iano += 1;
		}
		return ano;
		
	}
	
	public  ArrayList<Object> ListaInforme(InformeForm frm){
		
		try{
	        grInforme = new ArrayList<Object>();
	        
	        cn = getConection();
	    	st = cn.createStatement();
	    	sSql = "SELECT p.*,IfNull(a.Descripcion,'') as Descripcion,ifNull(a.valor,0) as valor FROM actfijo_proceso_det as p";
	    		sSql+= " LEFT JOIN actfijo_activofijo as a";
	    		sSql+= " ON a.IDActivo = p.IDActivo";
	    	if (frm.getMes()!=null){
	    		sSql+= " WHERE p.Folio='" + frm.getProceso() + "'";
	    	}
	    	if (frm.getMes()!=null) {
	    		sSql+=  " AND p.mes='" + frm.getMes() +  " '";
	    	}
	    	if (frm.getAno()!=null) {
	    		sSql+=  " AND p.ano='" + frm.getAno() + "'";
	    	}
	    	if (frm.getActivoFijo()!=null) {
	    		sSql+=  " AND a.IdActivo='" + frm.getActivoFijo() + "'";
	    	}
	    	if (frm.getUbicacion()!=null) {
	    		sSql+=  " AND a.IDUbicacion='" + frm.getUbicacion() + "'";
	    	}
	    	if (frm.getResponsable()!=null) {
	    		sSql+=  " AND a.IDResp='" + frm.getResponsable() + "'";
	    	}
	    	
	    	ResultSet rs = st.executeQuery(sSql);
	    	
	    	GenInformeForm  bInf;
	    	while(rs.next()){
	    		bInf  = new GenInformeForm();
	    		bInf.setProceso(rs.getObject("folio").toString());
	    		bInf.setActivo(rs.getObject("idactivo").toString() + " - " + rs.getObject("descripcion").toString());
	    		bInf.setAno(rs.getObject("ano").toString());
	    		bInf.setMes(rs.getObject("mes").toString());
	    		bInf.setFactor(rs.getObject("factor").toString());
	    		bInf.setValor(rs.getObject("valor").toString());
	    		bInf.setCorrecion(rs.getObject("valorcorreccion").toString());
	    		bInf.setValorActualizado(rs.getObject("valorcorregido").toString());
	    		bInf.setDepreEjercicio(rs.getObject("valordepreciacion").toString());
	    		bInf.setDepreAcum(rs.getObject("valordepreciacionacum").toString());
	    		bInf.setCorrecionDepre( rs.getObject("valordepreciacioncorregida").toString());
	    		
	    		grInforme.add(bInf);
	    		
    		}
	    	st.close();
	    	cn.close();	
    	}catch (Exception e){
    		e.printStackTrace();
    	}
    	
    	return grInforme;
		
		
		
	}
}

